package com.zz.common.utils.convert;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zz.common.utils.convert.dto.LocaleValue;

public class I18nConvertUtil {
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    /**
     * LocaleValue 转 JSON 字符串
     */
    public static String toJson(LocaleValue localeValue) {
        try {
            return OBJECT_MAPPER.writeValueAsString(localeValue);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("LocaleValue 转 JSON 失败", e);
        }
    }

    /**
     * JSON 字符串 转 LocaleValue
     */
    public static LocaleValue fromJson(String json) {
        try {
            return OBJECT_MAPPER.readValue(json, LocaleValue.class);
        } catch (Exception e) {
            throw new RuntimeException("JSON 转 LocaleValue 失败", e);
        }
    }

}
